<template>
	<view class="content" style="padding-bottom: 162rpx;">
		<popup-active :visible.sync="showHonor" :popScreenList="popScreenList" @toPage="toPage"></popup-active>
		<view class="activeSign">
			<view class="title">{{ activity.activityName }}</view>
			<view class="massClass">
				活动场次：
				<text style="color: rgba(102, 100, 92, 0.5);">{{ activity.activityFrequency }}</text>
				<text class="tip">(报名活动请先选择场次)</text>
			</view>
			<view class="active-list-item">
				<view class="uni-list-cell uni-list-cell-pd checkList" v-for="(item, index) in timeAddressList" :key="index">
					<view class="selectLeft" @click="choose(item)">
						<image :src="item.signUpTotalQuantity ? srcImgChoose : srcImg"></image>
					</view>
					<view>
						<view class="list-item-time">
							<image class="imageClass" src="https://mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/group1.png"></image>
							<span class="time">{{ item.activityTime }}</span>
						</view>
						<view class="list-item-time">
							<image class="imageClass" src="https://mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/group2.png"></image>
							<span class="time">{{ item.activityAddress }}</span>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="margin: 0 40rpx;">
			<image class="activityimg" :src="activity.activityPic" mode="aspectFit"></image>
			<view v-html="activity.activityInfo"></view>
		</view>
		<view class="infoTop" v-if="from !== 'personal'">
			<view class="infoButton"><button class="infoButtonClick" @click="forbid(activity.activityId)" :disabled="disabled">报名</button></view>
		</view>

		<uni-popup ref="popup" type="center" class="wrap" v-if="from !== 'personal'">
			<view class="chat">
				<view class="input">
					<view class="item">
						<view class="label">
							<text>姓</text>
							<text>名</text>
						</view>
						<input class="uni-input" name="input" v-model="name" placeholder="请输入姓名" maxlength="20" />
					</view>
					<view class="item">
						<view class="label">
							<text>手</text>
							<text>机</text>
							<text>号</text>
						</view>
						<input class="uni-input" name="input" v-model="phone" maxlength="11" placeholder="请输入手机号" type="number" />
					</view>
				</view>
				<button class="btn baseBtn" @click.stop="add()">提交</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import http from '../../common/request.js';
import uniPopup from '@/components/uni-popup/uni-popup-reporat.vue';
import popupActive from '@/components/popup-activity/popup-activity.vue';
import {getCommonShareInfo} from '@/common/utils.js'
export default {
	onLoad(option) {
		this.id = option.activityId;
		this.from = option.from;
	},
	components: {
		uniPopup,
		popupActive
	},
	onShareAppMessage() {
		return getCommonShareInfo()
	},
	mounted() {
		this.activeList();
	},
	data() {
		return {
			id: '',
			from: '',
			activity: {},
			current: '',
			timeAddressList: [],
			disabled: false,
			name: '',
			phone: undefined,
			sessionId: '',
			activityId: '',
			popScreenList: [],
			showHonor: false,
			srcImg: '//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/unselect.png',
			srcImgChoose: '//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/selected.png'
		};
	},
	methods: {
		toPage(value) {
			http('/api/duiba/getNoLoginUrl?credits=0&redirect=' + value, { method: 'GET' }).then(result => {
				if (result.code == 200) {
					// #ifdef H5
					location.href = result.data;
					// #endif
					// #ifdef MP-WEIXIN
					uni.navigateTo({
						url: '../../home/web_view?url=' + encodeURIComponent(result.data),
						animationType: 'pop-in',
						animationDuration: 200
					});
					// #endif
				}
			});
		},
		choose(data) {
			// this.sessionId = ''
			// this.timeAddressList.forEach((item) => {
			// 	item.signUpTotalQuantity = 0
			// })
			if(data.signUpTotalQuantity) {
				data.signUpTotalQuantity = 0
				this.sessionId = '';
			} else {
				data.signUpTotalQuantity = 1
				this.sessionId = data.sessionId;
			}
		},
		activeList() {
			http('/api/activity/appActivityDetail', {
				method: 'GET',
				data: {
					activityId: this.id
				}
			}).then(result => {
				this.activity = result.data || {};
				this.disabled = !this.activity.activityStatus === '02';
				this.timeAddressList = this.activity.timeAddressList || [];
			});
		},
		radioChange(evt) {
			const index = evt.detail.value;
			const activity = this.timeAddressList[index];
			this.sessionId = activity.sessionId;
		},
		forbid(data) {
			if (!this.sessionId) {
				uni.showToast({
					title: '请先选择报名场次',
					icon: 'none'
				});
				return;
			}
			this.activityId = data;
			this.$refs.popup.open();
		},
		add() {
			if (!this.phone) {
				uni.showToast({
					title: '请填写手机号码',
					icon: 'none'
				});
				return;
			}
			if (!/^1[0-9]{10,10}$/.test(this.phone)) {
				uni.showToast({
					title: '请输入正确的手机号！',
					icon: 'none'
				});
				return;
			}
			if (!this.name) {
				uni.showToast({
					title: '请填写用户名',
					icon: 'none'
				});
				return;
			}

			http('/api/activity/signUp', {
				data: {
					sessionId: this.sessionId, // 场次id
					activityId: this.activityId, // 活动id
					name: this.name,
					mobile: this.phone
				},
				method: 'POST'
			}).then(
				result => {
					this.$refs.popup.close();
					if (result.code == 200) {
						uni.showToast({
							title: '活动报名成功',
							icon: 'none'
						});
						setTimeout(() => {
							const list = result.popScreen || [];
							if (list.length > 0) {
								this.showHonor = true;
								this.popScreenList = list;
							}
						}, 1000);
					}
				},
				result => {
					this.$refs.popup.close();
				}
			);
		}
	}
};
</script>

<style scoped lang="less">
.activeSign {
	margin: 24rpx 40rpx;
	border-radius: 12rpx;
	.title {
		line-height: 45rpx;
		color: #66645d;
		font-size: 32rpx;
		padding-bottom: 24rpx;
		background: #f7f7f7;
	}
	.massClass {
		padding: 24rpx 0 0 24rpx;
		color: rgba(102, 100, 93, 1);
		background: #fff;
		display: flex;
		align-items: center;
		border-radius: 12rpx 12rpx 0 0;
		.tip {
			font-size: 24rpx;
			color: #f39800;
			margin-left: 48rpx;
		}
	}
	.active-list-item {
		padding: 24rpx 24rpx;
		background: #fff;
		border-radius: 0 0 12rpx 12rpx;
	}
}
.chat {
	width: 670rpx;
	background: #fff;
	border-radius: 12rpx;
	min-height: 360rpx;
	position: relative;
	overflow: hidden;
	.input {
		padding: 40rpx 86rpx 60rpx 40rpx;
		background: #f7f7f7;

		.item {
			display: flex;
			align-items: center;
			// margin-bottom: 44rpx;
			padding: 20rpx 0 12rpx 0;
			.label {
				width: 120rpx;
				font-size: 30rpx;
				font-weight: bold;
				color: #66645d;
				line-height: 42rpx;
				margin-right: 24rpx;
				display: flex;
				justify-content: space-between;
			}
			.uni-input {
				width: 400rpx;
				height: 60rpx;
				background: #f7f7f7;
				border-radius: 12rpx;
				border: 1rpx solid #979797;
				margin: 0;
				font-size: 26rpx;
				padding-left: 12rpx;
			}
			&:last-child {
				margin-bottom: 0;
			}
		}
	}
}
.checkList {
	display: flex;
	align-items: center;
	font-size: 28rpx;
	color: rgba(102, 100, 93, 0.5);
	height: 136rpx;
	border-bottom: 1px solid rgba(102, 100, 93, 0.1);
	.selectLeft {
		width: 36rpx;
		height: 36rpx;
		margin-right: 24rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
}
.checkList:last-child {
	border-bottom: 1px solid #fff;
}
.time {
	margin-left: 12rpx;
	line-height: 40rpx;
}

.title {
	line-height: 100rpx;
	font-size: 36rpx;
}
.c-title {
	line-height: 100rpx;
	font-size: 26rpx;
}
.activityimg {
	width: 100%;
	margin-top: 10rpx;
}

.attention {
	display: flex;
	justify-content: flex-end;
	padding: 32rpx 20rpx 32rpx;
	color: rgba(178, 177, 174, 1);
	align-items: center;
	cursor: pointer;
}

.attentionText {
	margin-left: 14rpx;
	font-size: 24rpx;
}

.infoButton {
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 34px;
	font-weight: 400;
	color: rgba(102, 100, 93, 1);
	background: rgba(250, 204, 107, 1);
	border-radius: 12rpx;
}

.infoButton navigator {
	flex: 1;
}

.infoButton button {
	flex: 1;
	background: rgba(250, 204, 107, 1);
	border-radius: 12rpx;
}

.infoButton button::after {
	border: 0;
	color: rgba(102, 100, 93, 1);
}

.commentTitle {
	height: 94rpx;
	line-height: 94rpx;
	display: flex;
	justify-content: space-between;
	font-size: 28rpx;
	font-weight: 500;
	align-items: center;
	border-bottom: 1px solid rgba(102, 100, 93, 0.1);
	padding: 0 40rpx;
}

.commentTitle h3 {
	font-size: 32rpx;
}

.commentBox {
	padding: 0 40rpx 40rpx;
}

.infoButtonLine {
	font-weight: lighter;
	font-size: 48rpx;
	color: rgba(102, 100, 93, 0.5);
}

.commentLi {
	background: rgba(255, 255, 255, 1);
	border-radius: 12rpx;
	margin-top: 24rpx;
	padding: 20rpx;
}

.commentFirst {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.commentFirst image {
	width: 100rpx;
	height: 100rpx;
	border-radius: 50px;
}

.commentFirst h3 {
	flex: 1;
	font-size: 30rpx;
	font-weight: 400;
	color: rgba(102, 100, 93, 1);
	padding-left: 24rpx;
	line-height: 46rpx;
}

.commentIcon {
	font-size: 24rpx;
	font-weight: 400;
	color: rgba(178, 177, 174, 1);
	display: flex;
	justify-content: flex-start;
	margin-left: 20rpx;
}

.commentIcon image {
	width: 30rpx;
	height: 30rpx;
	margin-right: 12rpx;
}

.commentSecond {
	font-size: 28rpx;
	font-weight: 300;
	color: rgba(138, 140, 141, 1);
	padding-left: 14rpx;
	margin: 36rpx 0;
	line-height: 46rpx;
}

.commentThired {
	border-left: 1px solid rgba(138, 140, 141, 1);
	margin-bottom: 23rpx;
}

.commentThiredInfo {
	margin-top: 12rpx;
	line-height: 46rpx;
	padding-left: 20rpx;
	color: rgba(178, 177, 174, 1);
	font-size: 28rpx;
}

.imageClass {
	width: 30rpx;
	height: 30rpx;
	margin-top: 8rpx;
}
.infoTop {
	padding: 40rpx;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
}
.infoButtonClick {
	height: 82rpx;
	width: 100%;
	background: rgba(250, 204, 107, 1);
	line-height: 82rpx;
	text-align: center;
	font-size: 34rpx;
	color: #66645d;
}
.list-item-time {
	display: flex;
	margin-bottom: 12rpx;
	&:last-child {
		margin-bottom: 0;
	}
}
.check {
	margin-right: 24rpx;
}
.baseBtn {
	border-radius: 0 0 12rpx 12rpx;
	background-color: #f1f1f1;
	position: absolute;
	bottom: 0rpx;
	left: 0rpx;
	width: 100%;
	}
</style>
